package com.device.api;

import com.device.domain.vo.StationVo;
import com.device.service.DeviceService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.RequiresLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.share.common.core.web.domain.AjaxResult.success;

@Tag(name = "站点接口管理")
@RestController
@RequestMapping("/deviceApi")
public class DeviceApiController extends BaseController {
    @Autowired
    private DeviceService deviceService;

    @Operation(summary = "根据经纬度搜索附近门店（站点）")
    @RequiresLogin
    @GetMapping("/nearbyStation/{latitude}/{longitude}")
    public AjaxResult nearbyStation(
            @PathVariable String longitude,
            @PathVariable String latitude){
        List<StationVo> stationVoList =
                deviceService.nearbyStationList(longitude, latitude);
        return success(stationVoList);
    }

    /*
    * 下面这段代码是为了做门店的详情数据
    * */
    @Operation(summary = "根据id来获取门店详情")
    @GetMapping("/getStation/{id}/{latitude}/{longitude}")
    public AjaxResult getStation(@PathVariable Long id,
                                @PathVariable String latitude,
                                @PathVariable String longitude){
        StationVo stationVo = deviceService.getStation(id, latitude, longitude);
        return success(stationVo);
    }


    /**
     * 扫码充电
     */
    @Operation(summary = "扫码充电")
    @RequiresLogin
    @GetMapping("scanCharge/{cabinetNo}")
    public AjaxResult scanCharge(@PathVariable String cabinetNo) {
        return success(deviceService.scanCharge(cabinetNo));
    }
}
